#include<iostream>
#include<string>
#include<memory>
//抽象工厂模式

class Fruit
{
public:
    virtual void name() = 0;
};

enum class FruitType
{
    APPLE = 1,
    BINANA = 2
};
class Apple : public Fruit 
{
public:
    void name()override 
    {
        std::cout<<"苹果!"<<std::endl;
    }
};

class Binana :public Fruit
{
    void name()override 
    {
        std::cout<<"香蕉!"<<std::endl;
    }
};

class Factory
{
public:
    virtual std::shared_ptr<Fruit> get_fruit_factory(const FruitType& type) = 0;
};

class FruitFactory : public Factory
{
public:
    virtual std::shared_ptr<Fruit> get_fruit_factory(const FruitType& type)
    {
        if (type == FruitType::APPLE)
        {
            return std::make_shared<Apple>();
        }
    }
};

class FactoryProductor
{
public:
    static std::shared_ptr<Factory> create(const std::string& name)
    {
        if (name == "水果")
        {
            return std::make_shared<FruitFactory>();
        }
    }
};
int main()
{
    std::shared_ptr<Factory> ff = FactoryProductor::create("水果");
    std::shared_ptr<Fruit> f = ff->get_fruit_factory(FruitType::APPLE);
    f->name();
    return 0;
}
